window.linkableTable = function(jqNode){
    let ths = jqNode.find('tr:first').children('th');
    let fields = [];
    ths.each(function(thid){
        fields[thid] = $(this).text();
    });
    let trs = jqNode.find('tr:gt(0)');
    trs.each(function(){
        let tr = $(this);
        let tds = tr.children('td');
        tds.each(function(tdid){
            let field = fields[tdid];
            if (field === 'article_id'){
                let val = $(this).text();
                $(this).html("<a href='./manageEverything?col=article&filter={\"_id\":\""+val+"\"}'>"+val+"</a>");
            } else if (field === 'user_id'){
                let val = $(this).text();
                if (val)
                    $(this).html("<a href='./manageEverything?col=user&filter={\"_id\":\""+val+"\"}'>"+val+"</a>");
            } else if (field === 'produceUser'){
                let val = $(this).text();
                if (val){
                    let idlink = JSON.parse(val)._id;
                    $(this).html(val.replace(idlink, "<a href='./manageEverything?col=user&filter={\"_id\":\""+idlink+"\"}'>"+idlink+"</a>"));
                }
            } else if (field === 'url' || field === 'produceUrl' || field === 'portrait'){
                let val = $(this).text();
                if (val)
                    $(this).html("<a href='"+val+"' target='_blank'>"+val+"</a>");
            } else if (field === 't' || field === 'produceTime' || field === 'modifyTime' || field === 'signupdate' || field === 'publish'){
                let val = $(this).text();
                if (val)
                    $(this).html("<a href='javascript:;' onclick='window.switchTime(this)'>"+val+"</a>");
            }
        })
    });
};

window.switchTime = function(node){
    let txt = node.innerText;
    let outtxt = txt;
    if (txt.match(/^\d{8}-\d{6}-\d{3}$/)){
        outtxt = Date.parse(txt.substr(0,4)+'-'+txt.substr(4,2)+'-'+txt.substr(6,2)+'T'+txt.substr(9,2)+':'+txt.substr(11,2)+':'+txt.substr(13,2)+'.'+txt.substr(16,3)).toString();
    } else if (txt.match(/^\d{13}$/)) {
        outtxt = (new Date(parseInt(txt)-new Date().getTimezoneOffset() * 60000).toISOString()).replace(/Z/g, '').replace(/[-:]/g, '').replace(/[T\.]/g, '-');
    }
    node.innerText = outtxt;
};